package com.xq.cluster;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

/**
 * @author xq
 * @version 1.0
 * @date 2021/4/28 12:44
 * @description redis集群连接测试
 */
public class TestRedisCluster {
    public static final String HOST = "192.168.2.120";

    public static void main(String[] args) {
        Set<HostAndPort> nodes = new HashSet<>();
        nodes.add(new HostAndPort(HOST, 6390));
        nodes.add(new HostAndPort(HOST, 6391));
        nodes.add(new HostAndPort(HOST, 6392));
        nodes.add(new HostAndPort(HOST, 6393));
        nodes.add(new HostAndPort(HOST, 6394));
        nodes.add(new HostAndPort(HOST, 6395));
        // 创建集群连接
        JedisCluster jedisCluster = new JedisCluster(nodes);
        jedisCluster.set("key_cluster","cluster");
        System.out.println(jedisCluster.get("key_cluster"));
        // 关闭集群连接
        jedisCluster.close();
    }
}
